// Created by Xslt generator for Eclipse.
// XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.ba360.struts.action;

import java.util.Hashtable;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ba360.portal.categories.TestList;

/**
 * Action.java created by EasyStruts - XsltGen. http://easystruts.sf.net created
 * on 03-30-2004
 * 
 * XDoclet definition:
 * 
 * @struts:action validate="true"
 * @struts:action-forward name="/jsp/CategoryBrowser.jsp"
 *                        path="/jsp/CategoryBrowser.jsp" contextRelative="true"
 */
public class CategoryAction extends Action {

	// --------------------------------------------------------- Instance
	// Variables

	// --------------------------------------------------------- Methods

	/**
	 * Method execute
	 * 
	 * @param ActionMapping
	 *            mapping
	 * @param ActionForm
	 *            form
	 * @param HttpServletRequest
	 *            request
	 * @param HttpServletResponse
	 *            response
	 * @return ActionForward
	 * @throws Exception
	 */
	public static String SUCCESS = "success";

	public static String FAILURE = "failure";

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HttpSession session = request.getSession();

		/*if (session.getAttribute("CATLIST") == null) {

			DBConnectionImpl dbConn = new DBConnectionImpl();
			Connection conn = dbConn.getConnection();
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt
					.executeQuery("select category_id,name from categories where par_category_id is null");
			MainCat[] mainCat = new MainCat[7];
			Log.init(this.getClass());
			Log.info("Fetch Size:" + rs.getFetchSize());
			int count = 0;
			List catList = new ArrayList();

			while (rs.next()) {
				Statement stmt1 = conn.createStatement();
				String mainCatName = rs.getString("name");
				int mainCatId = rs.getInt("category_id");

				ResultSet rs1 = stmt1
						.executeQuery("select category_id,name from categories where par_category_id="
								+ rs.getInt("category_id"));
				ArrayList subCat = new ArrayList();
				while (rs1.next()) {
					String subCatName = rs1.getString("name");
					int subCatId = rs1.getInt("category_id");

					SubCatList subCatList = new SubCatList(subCatName, subCatId);

					subCat.add(subCatList);
				}
				rs1.close();
				MainCat mainCatTemp = new MainCat(mainCatName, subCat);
				mainCatTemp.setMainCatId(mainCatId);
				mainCat[count] = mainCatTemp;
				count = count + 1;

				catList.add(mainCat);
			}
			rs.close();
			rs = stmt.executeQuery("select name,category_id from categories");
			Hashtable categories = new Hashtable();
			Hashtable categoryIds = new Hashtable();
			while (rs.next()) {
				int mainCatId = rs.getInt("category_id");
				String catName = rs.getString("name");

				categories.put(mainCatId + "", catName);
			}
			rs.close();

			rs = stmt
					.executeQuery("select category_id,par_category_id from categories");
			while (rs.next()) {
				int catId = rs.getInt("category_id");
				int parentCatId = rs.getInt("par_category_id");
				Log.info(catId + "  " + parentCatId);
				categoryIds.put(catId + "", parentCatId + "");
			}
			rs.close();
			stmt.close();
			conn.close();*/
		if (session.getAttribute("CATLIST") == null) {
			Hashtable categories = (Hashtable)servlet.getServletContext().getAttribute("APALLCATEGORY");
			Hashtable categoryIds = (Hashtable)servlet.getServletContext().getAttribute("APCATIDS");
			TestList tl = (TestList)servlet.getServletContext().getAttribute("APCATLIST");
			
			session.setAttribute("ALLCATEGORY", categories);
			session.setAttribute("CATIDS", categoryIds);
			//TestList tl = new TestList(mainCat);
			session.setAttribute("CATLIST", tl);//catList);
		}
			

		/*	YellowPageAction ypa = new YellowPageAction();
			ypa.execute(mapping, form, request, response);
		}*/
		return mapping.findForward(SUCCESS);
		//throw new UnsupportedOperationException("Generated method
		// 'execute(...)' not implemented.");
	}

}